package com.laikan.reader.bookfriend.net;

import com.laikan.library.utils.SPUtil;
import com.laikan.reader.R;
import com.laikan.reader.bookfriend.utils.ImageUtils;
import com.socks.library.KLog;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lingyt on 2016/11/7.
 * 关注和粉丝的API
 */
public class AutherNetApi {

    /**
     * 获取关注列表
     * @param pageNo   页码
     * @param followerId 列表主人
     * @param callback
     */
    public static void getAttentionList(int pageNo, String followerId, BaseCallback callback) {

        String partUrl = getString(R.string.part_url_attention_list);
        Map<String, String> params = new HashMap<>();
        params.put("pageNo", String.valueOf(pageNo));
        params.put("followerId", followerId);
        params.put("sd", getSd());
        KLog.w("NetApiHelper","-----------------------------获取关注列表------------------------------");
        KLog.w("NetApiHelper","请求参数：pageNo = "+pageNo+" followerId = "+followerId+" sd = "+getSd());
        NetApiHelper.getInstence().doPost(partUrl, params, callback);
    }


    /**
     * 添加关注
     * @param objectId
     * @param callback
     */
    public static void addAttention(String objectId, BaseCallback callback) {

        String partUrl = getString(R.string.part_url_add_attention);
        Map<String, String> params = new HashMap<>();
        params.put("objectId", objectId);
        params.put("sd", getSd());

        KLog.w("NetApiHelper","-----------------------------添加关注------------------------------");
        KLog.w("NetApiHelper","请求参数：objectId = "+objectId+" sd = "+getSd());
        NetApiHelper.getInstence().doPost(partUrl, params, callback);
    }

    /**
     * 取消关注
     * @param objectId
     * @param callback
     */
    public static void delAttention(String objectId, BaseCallback callback) {

        String partUrl = getString(R.string.part_url_del_attention);
        Map<String, String> params = new HashMap<>();
        params.put("objectId", objectId);
        params.put("sd", getSd());
        KLog.w("NetApiHelper","-----------------------------取消关注------------------------------");
        KLog.w("NetApiHelper","请求参数：objectId = "+objectId+" sd = "+getSd());
        NetApiHelper.getInstence().doPost(partUrl, params, callback);
    }


    /**
     * 获取粉丝列表
     * @param pageNo
     * @param objectId
     * @param callback
     */
    public static void getFunsList(int pageNo,String objectId,BaseCallback callback){

        String partUrl = getString(R.string.part_url_funs_list);
        HashMap<String, String> params = new HashMap<>();

        params.put("pageNo",String.valueOf(pageNo));
        params.put("objectId",objectId);
        params.put("sd",getSd());

        KLog.w("NetApiHelper","-----------------------------获取粉丝列表------------------------------");
        KLog.w("NetApiHelper","请求参数：pageNo = "+pageNo+" objcectId = "+objectId+" sd = "+getSd());
        NetApiHelper.getInstence().doPost(partUrl,params,callback);
    }


    /**
     * 获取看点首页的数据
     * @param pageNo
     * @param callback
     */
    public static void getShorteList(int pageNo, BaseCallback callback){
        String partUrl = getString(R.string.part_url_shorte_list);
        HashMap<String, String> params = new HashMap<>();

        params.put("pageNo",String.valueOf(pageNo));
        params.put("sd",getSd());

        KLog.w("NetApiHelper","-----------------------------获取看点首页数据------------------------------");
        KLog.w("NetApiHelper","请求参数：pageNo = "+pageNo+" sd = "+getSd());
        NetApiHelper.getInstence().doPost(partUrl,params,callback);
    }

    /**
     * 获取个人主页数据
     * @param authorId
     * @param callback
     */
    public static void getHome(String authorId, int bookPageNo,int shortePageNo,BaseCallback callback){
        String partUrl = getString(R.string.part_url_auther_home);
        HashMap<String, String> params = new HashMap<>();

        params.put("authorId",authorId);
        params.put("sd",getSd());
        params.put("bookPageNo",String.valueOf(bookPageNo));
        params.put("bookPageSize","10");
        params.put("shortePageNo",String.valueOf(shortePageNo));
        params.put("shortePageSize","10");

        KLog.w("NetApiHelper","-----------------------------获取个人主页数据------------------------------");
        KLog.w("NetApiHelper","请求参数：authorId = "+authorId+" shortePageNo = "+shortePageNo+" bookPageNo = "+bookPageNo+" sd = "+getSd());
        NetApiHelper.getInstence().doPost(partUrl,params,callback);
    }


    /**
     * 获取token
     * @return
     */
    public static String getSd() {
        String token = SPUtil.getString("token", "");
        return token;
    }

    public static String getString(int resId){
        String str = ImageUtils.getContext().getResources().getString(resId);
        return str;
    }
}
